import Toast from 'react-native-root-toast'
import { pageHeight } from 'src/constants'

export function showToast (payload = {}) {
  if (payload.text) {
    this.toast && this.toast.destroy()
    this.toast = Toast.show(payload.text, {
      duration: payload.duration || Toast.durations.SHORT,
      position: -pageHeight / 2,
      animation: true,
      hideOnPress: true,
      onHidden: this.hideToast
    })
  }
}

export function hideToast () {
  this.toast && this.toast.destroy()
  this.toast = null
}
